﻿namespace FineCollection.Intf
{


    /// <summary>
    /// Key and value pair.
    /// </summary>
    /// <typeparam name="K">type of a key.</typeparam>
    /// <typeparam name="V">type of a value.</typeparam>
    /// <seealso cref="RMap{K,V}"/>
    public class MapEntry<K, V> : System.IEquatable<MapEntry<K,V>>
        where K : System.IEquatable<K>
    {
        public K Key { get; private set; }
        public V Value { get; internal set; }


        /// <summary>
        /// Trivial constructor.
        /// </summary>
        public MapEntry(K key, V value)
        {
            this.Key = key;
            this.Value = value;
        }


        public bool Equals(MapEntry<K, V> other)
        {
            return this.Key.Equals(other.Key)
                && this.Value.Equals(other.Value);
        }


        public override bool Equals(object obj)
        {
            if (obj is MapEntry<K, V>)
                return Equals(obj as MapEntry<K, V>);
            else
                return false;
        }


        public override int GetHashCode()
        {
            return Key.GetHashCode();
        }


        public override string ToString()
        {
            return Key.ToString() + '/' + Value.ToString();
        }


        public static implicit operator System.Collections.Generic.KeyValuePair<K, V>(MapEntry<K, V> kvp)
        {
            return new System.Collections.Generic.KeyValuePair<K, V>(kvp.Key, kvp.Value);
        }
    }

}